import { statisticVisit } from '~/api/mall'
import { generateSxspm } from '~/common/common'
import { getMyVip } from '~/api/identity'
import { getAstrict } from '~/api/volunteer'
import { hideLoading } from '~/components/loading/index'
import ls from 'store2'
const getMyVips = function(obj) {
  return getMyVip(obj)
}
const getAstricts = function(obj) {
  return getAstrict(obj)
}
export default {
  install(Vue) {
    ;(Vue.prototype.$visit = function(path, origin, events) {
      let sxspms = generateSxspm(path, origin, events)
      let sx_uids
      if (ls.get('userVoId')) {
        sx_uids = ls.get('userVoId')
      } else {
        sx_uids = ''
      }
      let obj = {
        sxspm: sxspms,
        sx_uid: sx_uids,
      }
      statisticVisit(obj)
        .then((res) => {})
        .finally(() => {})
    }),
      (Vue.prototype.$getVip = async function() {
        if (!ls.get('tokensyxk')) {
          sessionStorage.setItem('isVipStr', '')
          return
        }
        if (sessionStorage.getItem('isVipStr')) {
          return
        }
        this.$loading('open')
        this.isVipStr = ''
        let vipStatus = await getMyVips({ userType: ls.get('userType') })
        if (vipStatus.code == '0') {
          if (vipStatus.data.isVIP) {
            let vipListData = await getAstricts({ userType: ls.get('userType') })
            vipListData.data.forEach((item) => {
              this.isVipStr += item.service
            })
          }
        }
        sessionStorage.setItem('isVipStr', this.isVipStr)
        this.$loading('close')
      }),
      (Vue.prototype.$hideLoading = function() {
        setTimeout(() => {
          hideLoading()
        }, 1000)
      })
  },
}
